"""
备份文件
while True :
    arr = sourcefile.read(1024)
    if len(arr) == 0 :
        break
    targetFile.writ(arr)
"""
fileName = 'test.txt'
#拿到后缀
pointIndex = fileName.rfind('.')
prefix = fileName[pointIndex:] # .txt
print(prefix)
newFileName = fileName[:pointIndex]+'[备份]'+prefix #test[备份].txt
print(newFileName) #

source = open(fileName,mode='rb')
targetFile = open(newFileName,mode='wb')

while True:
    con = source.read(1024)
    if len(con) == 0 : # 如果数组里面没有数据了就退出
        break
    targetFile.write(con)

source.close()
targetFile.close()